package com.nulldev.util.net.experimental.udp2;

import java.util.Arrays;

public class SplitMessage implements Comparable<SplitMessage> {
	private int sequenceId;
    private byte[] data;
    private long createTime;

    public SplitMessage() {
    }

    public SplitMessage(int sequenceId, byte[] data) {
        this.sequenceId = sequenceId;
        this.data = data;
        createTime = System.currentTimeMillis();
    }

    public void setValues(int sequenceId, byte[] data) {
        this.sequenceId = sequenceId;
        this.data = data;
        createTime = System.currentTimeMillis();
    }

    public Integer getSequenceId() {
        return sequenceId;
    }

    public byte[] getData() {
        return data;
    }

    public long getCreateTime() {
        return createTime;
    }

    @Override
    public int compareTo(SplitMessage o) {
        return this.sequenceId > o.sequenceId ? -1 : this.sequenceId < o.sequenceId ? 1 : 0;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SplitMessage that = (SplitMessage) o;

        if (sequenceId != that.sequenceId) return false;
        if (!Arrays.equals(data, that.data)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = sequenceId;
        result = 31 * result + Arrays.hashCode(data);
        return result;
    }
}
